import React,{Component} from 'react'
import { Table,message } from 'antd';
export default class user extends Component{
    constructor(props){
        super(props);
        this.state = {
            dataSource:[]
        }
    }
    //获取用户信息
    componentWillMount() {
        var result=[];
        this.axios.get("/user/findUserAll").then(res=>{
            const data=res.data.result
           if(res.data.code===200){
               data.forEach((item,index)=>{
                   let obj={
                       key:index,
                       _id:item._id,
                       usr:item.usr,
                       pwd:item.pwd
                   }
                   result.push(obj)
               })
               this.setState({
                   dataSource :result
               })
           }else{
              message.error("没有对应数据");
           }
        })
    }
    render(){
        const columns = [
            {
                title: '序号',
                dataIndex: '_id',
                key: '_id',
            },
            {
                title: '用户名',
                dataIndex: 'usr',
                key: 'usr',
            },
            {
                title: '密码',
                dataIndex: 'pwd',
                key: 'pwd',
            },
        ];
        return(
            <div className="userContent">
                <Table dataSource={this.state.dataSource} columns={columns} bordered/>
            </div>
        )
    }
}